<template>
  <div class="create-container">
    <div class="right-container">
      <!---->
      <el-form :inline="true" ref="listQuery" :model="listQuery" status-icon label-position="right" class="demo-form-inline"
               label-width="140px" style="width:40%;">
        <el-form-item label="配置名称：" prop="cfgName">
          <el-input v-model="listQuery.cfgName" placeholder="配置名称"/>
        </el-form-item>
        <el-form-item label="配置值：" prop="cfgValue">
          <el-input v-model="listQuery.cfgValue" placeholder="配置值"/>
        </el-form-item>
        <el-form-item>
          <el-button class="filter-item" type="primary" icon="el-icon-edit" @click="handleEdit">设置参数</el-button>
        </el-form-item>
      </el-form>

      <el-table v-loading="listLoading" :data="list" ref="cargoTable" element-loading-text="正在查询中。。。" border fit highlight-current-row
                :header-cell-style="{background:'#F2F2F2',color:'#666'}">
        <el-table-column align="left" min-width="130" label="配置名称" prop="cfgName"/>
        <el-table-column align="left" min-width="120" label="配置值" prop="cfgValue"/>
      </el-table>
      <!--<pagination v-show="total>0" :total="total" :page.sync="listQuery.pageNum" :limit.sync="listQuery.pageSize"
                  @pagination="queryList" style="margin: 0"/>-->

    </div>
  </div>
</template>

<script>
import {doGet, doPost} from '@/api'
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination

export default {
  name: 'usersearch',
  components: { Pagination },
  data() {
    return {
      list: [],
      total: 0,
      listQuery: {
        cfgName: undefined,
        cfgValue: undefined
      },
      listLoading: true,
    }
  },
  created() {
    this.queryList()
  },
  methods: {
    queryList() {
      this.listLoading = true
      doGet('config.html?op=search', {}).then(response => {
        this.list = response.rows
        /*this.total = response.data.totalcount*/
        this.listLoading = false
      }).catch(() => {
        this.list = []
        /*this.total = 0*/
        this.listLoading = false
      })
    },
    handleEdit() {
      this.$refs['listQuery'].validate(valid => {
        if (valid) {
          doGet('config.html?op=set', this.listQuery).then(response => {
            this.queryList()
            this.$notify.success({
              title: '成功',
              message: '系统参数设置成功'
            })
          }).catch(response => {
            this.$notify.error({
              title: '失败',
              message: response.message
            })
          })
        }
      })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
</style>
